using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Ai;


namespace HengTong.ViewModel._Admin.SysPromptVms
{
    public partial class SysPromptListVm : BaseListVm<SysPromptView, SysPromptSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPromptView>> InitGridHeader()
        {
            return new List<GridColumn<SysPromptView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.GroupName),
                this.MakeGridHeader(x => x.SystemPrompt),
                this.MakeGridHeader(x => x.UserPrompt),
                this.MakeGridHeader(x => x.Version),
                this.MakeGridHeader(x => x.SortOrder),
                this.MakeGridHeader(x => x.IsEnabled),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPromptView> GetSearchQuery()
        {
            var query = DC.Set<SysPrompt>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.Code, x=>x.Code)
                .CheckContain(Searcher.Description, x=>x.Description)
                .CheckEqual(Searcher.GroupId, x=>x.GroupId)
                .CheckContain(Searcher.SystemPrompt, x=>x.SystemPrompt)
                .CheckContain(Searcher.UserPrompt, x=>x.UserPrompt)
                .CheckEqual(Searcher.Version, x=>x.Version)
                .CheckEqual(Searcher.SortOrder, x=>x.SortOrder)
                .CheckEqual(Searcher.IsEnabled, x=>x.IsEnabled)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new SysPromptView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    Description = x.Description,
                    GroupName = x.Group.Name,
                    SystemPrompt = x.SystemPrompt,
                    UserPrompt = x.UserPrompt,
                    Version = x.Version,
                    SortOrder = x.SortOrder,
                    IsEnabled = x.IsEnabled,
                    Remark = x.Remark,
                })
                .OrderBy(x => x.ID);
            return query;
        }
    }

    public class SysPromptView : SysPrompt{
        [Display(Name = "分组名称")]
        public String GroupName { get; set; }

    }
}
